﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Job.Web.Framework;
using Job.Entity;
using Job.Logic.Personal;
using Job.Logic.Common;

namespace Job.Web.Person
{
    public partial class PersonManager : BasePage
    {
        int ctrlId = myR["ctrlId"].IntValue;
        bool reset = myR["reset"].BoolValue;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (reset)
            {
                tbMain.Visible = false;
                tbForgetPwd.Visible = true;
            }
            else
            {
                tbMain.Visible = true;
                tbForgetPwd.Visible = false;
                MySession session = new MySession();
                if (session.GetPersonalFromSession() == null
                    || session.GetPersonalFromSession().PersonAccountid <= 0)
                {
                    string url = WebCommon.GetApplicationPath(Request) + "Person/PersonLogin.aspx?categoryid=1&error=1";
                    Response.Redirect(url);
                    return;
                }
                else
                {
                    this.LoadControls();
                }
            }
        }

        private void LoadControls()
        {
            string fileName = "~/userControls/Personal/ResumeCenter.ascx";
            switch (ctrlId)
            {
                case (int)Constants.ResumeManagerType.CreateResume:
                    fileName = "~/userControls/Personal/CreateResume.ascx";
                    break;
                case (int)Constants.ResumeManagerType.ResumeCenter:
                    fileName = "~/userControls/Personal/ResumeCenter.ascx";
                    break;
                case (int)Constants.ResumeManagerType.HunterSearch:
                    fileName = "~/userControls/Personal/SearchHunterJob.ascx";
                    break;
                case (int)Constants.ResumeManagerType.SendHistory:
                    fileName = "~/userControls/Personal/PersonSendList.ascx";
                    break;
                case (int)Constants.ResumeManagerType.FavoritesHistory:
                    fileName = "~/userControls/Personal/PersonFavouritesList.ascx";
                    break;
                case (int)Constants.ResumeManagerType.AccountModify:
                    fileName = "~/userControls/Personal/AccountModify.ascx";
                    break;
                case (int)Constants.ResumeManagerType.PasswordEdit:
                    fileName = "~/userControls/Personal/EditPassword.ascx";
                    break;
                default:
                    fileName = "~/userControls/Personal/AccountInfo.ascx";
                    break;

            }

            this.LoadCtrl(fileName, "phResume");
        }

        protected void btnSend_Click(object sender, EventArgs e)
        {
            PersonalLogic pl = new PersonalLogic();
            JobPersonAccount account = pl.GetAccountByEmail(txtEmail.Text.Trim());
            if (account != null && account.PersonAccountId > 0)
            {
                MailObject obj = new MailObject()
                {
                    MailContent = account.UserName + ":<br> 您好！<br> 您在无忧才智网站的登录密码为：<strong>"
                        + account.Password.Trim()
                        + "</strong>，请点击<a href='http://www.wyhrm.com' target='_blank'>这里</a>登录！感谢您对我们的关心与支持。",
                    Subject = "无忧才智登录密码",
                    MailTo = account.LinkEmail

                };
                CommonLogic.SendMail(obj);
                lblMessage.Text = "已将您的登录密码发到到邮箱，请查看邮件获得密码！";
                //string url = WebCommon.GetApplicationPath(Request) + "Person/PersonLogin.aspx";
                //Response.Redirect(url);
            }
            else
            {
                lblMessage.Text = "此EMAIL地址没有注册！请重新输入!";
            }
        }
    }
}
